<?php
if ( !defined( "IN_OP" ) )
{
    exit( "You can't access this file directly..." );
}
if ( ( $curruser['acl'] < 255 || $curruser['acl'] == 255 && $curruser['prev_id'] != 0 ) && !SubAccountRight( $curruser, 1 ) )
{
    diemsg( "你不是管理者！" );
}
$ui = new UI();
$tpl = new Template2();
$conf = new Config();
$rs = getdb( "select * from lotto where open>='".date( "Y-m-d" )."' order by open" );
if ( $rs->eof )
{
    $ui->showErrorPage( "<p class=error>目前没有可以下注期数！</p>" );
    exit();
}
$open = $rs->f['open'];
$round = $rs->f['round'];
$lotto_id = $rs->f['id'];
$opnumber = $rs->f['n1'];
$rs->close();
$stopbet = $conf->get( "stopbet" );
$startmode = "";

if ( date( "Y-m-d" ) < $open )
{
    $startmode = "disabled";
}
else if ( date( "Y-m-d" ) == $open )
{
    if ( $stopbet <= date( "Hi" ) && 0 < $opnumber )
    {
        $startmode = "disabled";
    }
    else if ( date( "Hi" ) <= $conf->get( "startbet" ) )
    {
        $startmode = "disabled";
    }
}
$dt = date( "Y-m-d" );
$t1 = strtotime( $open." ".$stopbet );
$tpl->Set( array( "timestap" => $t1 - systime( ), "phptime" => systime( ), "open" => $open, "round" => d3( $round ), "dt" => $dt, "lotto_id" => $lotto_id ) );
$split = 1;
$ratemod = 2;
$disk_code = "a";
$diskStr = "";
include( "class_6h/BetTotal_6h.php" );
$BetTotal_6h = new BetTotal_6h( $lotto_id );
$dataTotalArr = array();
$showDataArr = array();
$i = 1;
while ( $i < 12 )
{
    $showDataArr[$i] = array();
    $showDataArr[$i]['1'] = array( "numbers" => "{$i}_1", "totalnum" => 0, "amount" => 0, "amount_rate" => 0, "rate" => 0, "back1" => 0, "back2" => 0, "winlost" => 0, "namount" => "" );
    $showDataArr[$i]['2'] = array( "numbers" => "{$i}_2", "totalnum" => 0, "amount" => 0, "amount_rate" => 0, "rate" => 0, "back1" => 0, "back2" => 0, "winlost" => 0, "namount" => "" );
    $dataTotalArr[$i] = array( "bettype" => $i, "totalnum" => 0, "amount" => 0, "amount_rate" => 0, "back1" => 0, "back2" => 0 );
    ++$i;
}

$theacl = $curruser['acl'];
$userid = $curruser['id'];
$showid = $theacl == 255 ? "0" : $userid;
$bettypeStr = "19";
$sql = $BetTotal_6h->getDataListByNumSsSQL( $lotto_id, $bettypeStr, $showid, $diskStr, $split, $ratemod );
$rs = getdb( $sql );
$updatetime = systime( ) - 30;

while ( !$rs->eof )
{
	
    $bettype = $rs->f['bettype'];
    $n = substr( $rs->f['numbers'], 0, 1 );
    $i = intval( substr( $rs->f['numbers'], 2, 2 ) );
	
    $showDataArr[$i][$n]['totalnum'] = $rs->f['totalnum'];
    $showDataArr[$i][$n]['amount'] = $rs->f['amount'];
    $showDataArr[$i][$n]['amount_rate'] = $rs->f['amount_rate'];
    $showDataArr[$i][$n]['rate'] = $rs->f['rate'];
	/* $dataTotalArr[$i] += "totalnum";
    $dataTotalArr[$i] += "amount";
    $dataTotalArr[$i] += "back1";//旧的
    $dataTotalArr[$i] += "back2"; */
    $dataTotalArr[$i]['totalnum'] += $rs->f['totalnum'];
    $dataTotalArr[$i]['amount'] += $rs->f['amount'];
    $dataTotalArr[$i]['back1'] += $rs->f['back1'];
    $dataTotalArr[$i]['back2'] += $rs->f['back2'];
	
    $rs->next();
}

$rs->close();
$rs = getdb( "select * from rate1a where lotto_id={$lotto_id}" );
if ( $rs->eof )
{
    $ui->showErrorPage( "<p class=error>系统目前维护中，请稍後！</p>" );
    exit();
}
$i = 1;
while ( $i < 12 )
{
    $idx = d2( $i );
    $showDataArr[$i][1]['rate'] = $rs->f["r19_1_{$idx}"] - 0;
    $showDataArr[$i][2]['rate'] = $rs->f["r19_2_{$idx}"] - 0;
    $winlost1 = round( $dataTotalArr[$i]['amount'] - $showDataArr[$i]['1']['amount_rate'] - $dataTotalArr[$i]['back1'] + $dataTotalArr[$i]['back2'] );
    $winlost2 = round( $dataTotalArr[$i]['amount'] - $showDataArr[$i]['2']['amount_rate'] - $dataTotalArr[$i]['back1'] + $dataTotalArr[$i]['back2'] );
    $tpl->set( array( "r19_1_{$idx}" => $showDataArr[$i][1]['rate'], "r19_2_{$idx}" => $showDataArr[$i][2]['rate'], "money1{$idx}" => round( $showDataArr[$i][1]['amount'] ), "win1{$idx}" => show_numbercolor( $winlost1 ), "money2{$idx}" => round( $showDataArr[$i][2]['amount'] ), "win2{$idx}" => show_numbercolor( $winlost2 ) ) );
    ++$i;
}
$rs->close();
$i = 1;
while ( $i <= 12 )
{
    $tpl->set( "num".$i, implode( ", ", array_values( $g_chinayearnumpic6[$i] ) ) );
    ++$i;
}
$b41 = isset( $_COOKIE['b41'] ) ? $_COOKIE['b41'] : "";
$b42 = isset( $_COOKIE['b42'] ) ? $_COOKIE['b42'] : "";
$b43 = "";
$tpl->set( array( "b41" => $b41, "b42" => $b42, "b43" => $b43, "startnowdisable" => $startmode ) );
$prot_user = array();
$j = 0;
$i = 0;
while ( $i < 10 )
{
    $name = $conf->get( "port_systemuser_".$i );
    if ( $name != "" )
    {
        $prot_user[$j] = $name;
        ++$j;
    }
    ++$i;
}
include_once( "class_6h/class.menu.php" );
$fieldArr = array( "round" => $round, "open" => $open, "lotto_id" => $lotto_id, "split_id" => 1 );
$onlineMenu = new menu_6h( 2, $fieldArr );
$selectid = getvar( "select" ) == "" ? 0 : getvar( "select" );
$menuList = $onlineMenu->getMenu( $selectid );
$tpl->set( "menuList", $menuList );
$tpl->set( "selectid", $selectid );
unset( $onlineMenu );
$userrame1 = "&nbsp;<select name=account style='display:none'><option value='' selected> </option>";
$i = 0;
while ( $i < $j )
{
    $userrame1 .= "<option value='{$prot_user[$i]}'>{$prot_user[$i]}</option>";
    ++$i;
}

$userrame1 .= "</select>";
$tpl->set( "select_usr1", $userrame1 );
$tpl->load( "main", "unow4.htm" );
$tpl->set( "jslang", $g_conf['language'] );
$tpl->show( "main" );
$ui->footer();
?>